//
//  ICRobotViewCell.m
//  ICome
//
//  Created by chenqs on 2017/7/21.
//  Copyright © 2017年 iCom. All rights reserved.
//

#import "ICRobotViewCell.h"
#import "ICRobotModel.h"
#import "ICHeaderFile.h"

static const CGFloat IconImageViewWH = 36.;
static const CGFloat RobotViewCellGap = 10.;
static const CGFloat RobotViewCellHeight = 55.;

@interface ICRobotViewCell ()
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;

@property (nonatomic, strong) UIView *lineView;
@end

@implementation ICRobotViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews
{
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(RobotViewCellGap, (RobotViewCellHeight-IconImageViewWH)/2 , IconImageViewWH, IconImageViewWH)];
    _iconImageView.image = [UIImage imageNamedFromiComeSDKBundle:@"calendar_meet"];
    _iconImageView.layer.cornerRadius = 8.;
    _iconImageView.clipsToBounds = YES;
    [self.contentView addSubview:_iconImageView];
    
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.right+10., (RobotViewCellHeight-16-2.)/2, kScreenWidth-_nameLabel.left-20., 16+2.)];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.font = [UIFont systemFontOfSize:16];
    _nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    [self.contentView addSubview:_nameLabel];
    
    
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(RobotViewCellGap, RobotViewCellHeight-0.5, kScreenWidth, 0.5)];
    _lineView.backgroundColor = [UIColor colorWithHexString:@"#d9d9d9"];
    [self.contentView addSubview:_lineView];
}

- (void)setIsLast:(BOOL)isLast
{
    if (isLast) {
        _lineView.x = 0;
    }else
    {
        _lineView.x = RobotViewCellGap;
    }
}

- (void)setObject:(id)object
{
    if (object && [object isKindOfClass:[ICRobotModel class]]) {
        
        ICRobotModel *model = (ICRobotModel *)object;
        [_iconImageView sd_setImageWithURL:[NSURL URLWithString:[ICTools getFileMaxImageURL:(model.photoId)]] placeholderImage:[UIImage imageNamedFromiComeSDKBundle:@"icon_ework_banner_default"] options:SDWebImageRetryFailed];
        _nameLabel.text = model.botName;
    }
}


+ (CGFloat)setRobotViewCellHeight
{
    return RobotViewCellHeight;
}
@end
